<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回由所有已定义变量所组成的数组</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.get-defined-vars" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">get_defined_vars</h1>
    <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">get_defined_vars</span> &mdash; <span class="dc-title">
     返回由所有已定义变量所组成的数组
    </span></p>

   </div>
   <div class="refsect1 unknown-unknown-seealsq" id="refsect1-function.get-defined-vars-unknown-unknown-seealsq">
    <h3 class="title">描述</h3>
     <div class="methodsynopsis dc-description">
      <span class="methodname"><strong>get_defined_vars</strong></span>
       ( <span class="methodparam">void</span>
      ) : <span class="type">array</span></div>

    <p class="para rdfs-comment">
     此函数返回一个包含所有已定义变量列表的多维数组，这些变量包括环境变量、服务器变量和用户定义的变量。
     <div class="informalexample">
      <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$b&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #0000BB">1</span><span style="color: #007700">,</span><span style="color: #0000BB">1</span><span style="color: #007700">,</span><span style="color: #0000BB">2</span><span style="color: #007700">,</span><span style="color: #0000BB">3</span><span style="color: #007700">,</span><span style="color: #0000BB">5</span><span style="color: #007700">,</span><span style="color: #0000BB">8</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">get_defined_vars</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">//&nbsp;打印&nbsp;$b<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">[</span><span style="color: #DD0000">"b"</span><span style="color: #007700">]);<br /><br /></span><span style="color: #FF8000">//&nbsp;打印&nbsp;PHP&nbsp;解释程序的路径（如果&nbsp;PHP&nbsp;作为&nbsp;CGI&nbsp;使用的话）<br />//&nbsp;例如：/usr/local/bin/php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$arr</span><span style="color: #007700">[</span><span style="color: #DD0000">"_"</span><span style="color: #007700">];<br /><br /></span><span style="color: #FF8000">//&nbsp;打印命令行参数（如果有的话）<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">[</span><span style="color: #DD0000">"argv"</span><span style="color: #007700">]);<br /><br /></span><span style="color: #FF8000">//&nbsp;打印所有服务器变量<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">[</span><span style="color: #DD0000">"_SERVER"</span><span style="color: #007700">]);<br /><br /></span><span style="color: #FF8000">//&nbsp;打印变量数组的所有可用键值<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">array_keys</span><span style="color: #007700">(</span><span style="color: #0000BB">get_defined_vars</span><span style="color: #007700">()));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
      </div>

     </div>
    </p>
    <p class="para">
     参见 <span class="function"><a href="get_defined_functions.html" class="function">get_defined_functions()</a></span> 和
     <span class="function"><a href="get_defined_constants.html" class="function">get_defined_constants()</a></span>。
    </p>
   </div>

  </div></div></div></body></html>